﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Newtonsoft.Json;

namespace AsTekMobile
{
    public partial class frmLogin : Form
    {
        public int GuncellemeSuresi { get; set; }

        public frmLogin()
        {
            InitializeComponent();
        }

        private void frmLogin_Load(object sender, EventArgs e)
        {
            Yukle();
            txtSifre.Focus();
        }

        private void Yukle()
        {
            try
            {
                var sonuc = Database.ctor.Kullanicilar;
                cmbTeknisyen.DataSource = sonuc;
                cmbTeknisyen.DisplayMember = "Adi";
            }
            catch (Exception ex)
            {
                ErrorMgr.Opps(ex);
            }
        }

        private void btnGiris_Click(object sender, EventArgs e)
        {
            KullaniciKontrol();
        }

        private void KullaniciKontrol()
        {
            if (cmbTeknisyen.SelectedIndex > -1)
            {
                User usr = (User)cmbTeknisyen.SelectedItem;
                if (usr.Sifre == txtSifre.Text)
                {
                    Program.Session[Settings.TeknikServisID] = usr.ID;
                    GuncellemeSuresi = usr.GuncellemeSuresi;
                    this.DialogResult = DialogResult.OK;
                }
                else
                {
                    MessageBox.Show("Şifre hatalı !");
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void txtSifre_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                try
                {
                    KullaniciKontrol();
                }
                catch (Exception ex)
                {
                    ErrorMgr.Opps(ex);
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (Sip.Visible)
            {
                Sip.Visible = false;
            }
            else
            {
                Sip.Visible = true;
            }
        }
    }
}